package org.anyin.gitee.shiro.controller;

import lombok.extern.slf4j.Slf4j;
import org.anyin.gitee.shiro.base.BusinessCodeEnum;
import org.anyin.gitee.shiro.base.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Executor;

@RestController
@RequestMapping("/log-test")
@Slf4j
public class LogTestController {

    @Autowired
    private Executor executor;

    @GetMapping("/success")
    public Response<String> success(){
        return new Response<>("success");
    }

    @GetMapping("/business-exception")
    public Response<String> businessException(){
        throw BusinessCodeEnum.PWD_NOT_MATCH.getException();
    }

    @GetMapping("/system-exception")
    public Response<String> systemException(){
        throw new NullPointerException("空指针异常");
    }

    @GetMapping("/executor")
    public Response<String> executor(){
        log.info("before executor execute");
        executor.execute(() -> {
            log.info("this executor execute method");
        });
        log.info("after executor execute");
        return new Response<>("success");
    }
}
